package com.xucy.springboot.designmodel.creational.prototype;

import java.io.IOException;

/**
 * @Author xucy
 * @Date 2019-07-17 16:18
 * @Description 原型模式 (原型模式创建的对象也是需要花费内存的)
 **/

public class Test {

    public static void main(String[] args) throws CloneNotSupportedException, IOException, InterruptedException {
        Email email=new Email();
        email.setEmailContent("上去把");

        Thread.sleep(2000);

        for(int i=0;i<10000;i++){
            Email email1=(Email)email.clone();
            System.out.println(email1.hashCode()+":"+email.hashCode());
            email1.setEmailName("xu"+i);
            email1.setEmailAddress("xu"+i+"@qq.com");
            email1.setEmailContent("上去把"+i);
            EmailUtil.sendEmail(email1);
        }

        EmailUtil.saveEmailContent(email);

            Thread.sleep(2000);


        for(int i=0;i<10000;i++){
            Email email1=new Email();
            System.out.println(email1.hashCode()+":"+email.hashCode());
            email1.setEmailName("xu"+i);
            email1.setEmailAddress("xu"+i+"@qq.com");
            email1.setEmailContent("上去把"+i);
            EmailUtil.sendEmail(email1);
        }

        Thread.sleep(2000);

        for(int i=0;i<10000;i++){
            Email email1=(Email)email.clone();
            System.out.println(email1.hashCode()+":"+email.hashCode());
            email1.setEmailName("xu"+i);
            email1.setEmailAddress("xu"+i+"@qq.com");
            email1.setEmailContent("上去把"+i);
            EmailUtil.sendEmail(email1);
        }

        Thread.sleep(50000);
    }
}
